wait_timeout = "80"

QC_http_cmd = [
    {
        "cmd": 'AT+QIDEACT=1',
        "match": 'AT\+QIDEACT=1\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QFDEL="1.txt"',
        "match": '.*',
    },
    {
        "cmd": 'AT+QHTTPCFG="requestheader",0',
        "match": 'AT\+QHTTPCFG="requestheader",0\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QSSLCFG="sslversion",1,4',
        "match": 'AT\+QSSLCFG="sslversion",1,4\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QSSLCFG="ciphersuite",1,0XFFFF',
        "match": 'AT\+QSSLCFG="ciphersuite",1,0XFFFF\s{3}OK\s{2}',
    },
    # HTTP基本命令
    {
        "cmd": 'AT+QHTTPCFG=?',
        "match": "\s{2}OK\s{2}",
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="contextid"',
        "match": 'AT\+QHTTPCFG="contextid"\s{3}\+QHTTPCFG: "contextid",1\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="requestheader"',
        "match": 'AT\+QHTTPCFG="requestheader"\s{3}\+QHTTPCFG: "requestheader",0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="responseheader"',
        "match": 'AT\+QHTTPCFG="responseheader"\s{3}\+QHTTPCFG: "responseheader",\d\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="sslctxid"',
        "match": 'AT\+QHTTPCFG="sslctxid"\s{3}\+QHTTPCFG: "sslctxid",1\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="contenttype"',
        "match": 'AT\+QHTTPCFG="contenttype"\s{3}\+QHTTPCFG: "contenttype",0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="rspout/auto"',
        "match": 'AT\+QHTTPCFG="rspout/auto"\s{3}\+QHTTPCFG: "rspout/auto",0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="closed/ind"',
        "match": 'AT\+QHTTPCFG="closed/ind"\s{3}\+QHTTPCFG: "closed/ind",0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPURL=?',
        "match": 'AT\+QHTTPURL=\?\s{3}\+QHTTPURL: \(1-2048\),\(1-65535\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPURL?',
        "match": "\s{2}OK\s{2}",
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPGET=?',
        "match": 'AT\+QHTTPGET=\?\s{3}\+QHTTPGET: \(1-65535\),\(1-2048\),\(1-65535\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPGETEX=?',
        "match": 'AT\+QHTTPGETEX=\?\s{3}\+QHTTPGETEX: \(1-65535\),<start_position>,<read_len>\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPPOST=?',
        "match": 'AT\+QHTTPPOST=\?\s{3}\+QHTTPPOST: \(1-1024000\),\(1-65535\),\(1-65535\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPPOSTFILE=?',
        "match": 'AT\+QHTTPPOSTFILE=\?\s{3}\+QHTTPPOSTFILE: <file_name>,\(1-65535\)\[,\(0-2\)\]\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPREAD=?',
        "match": 'AT\+QHTTPREAD=\?\s{3}\+QHTTPREAD: \(1-65535\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPREADFILE=?',
        "match": 'AT\+QHTTPREADFILE=\?\s{3}\+QHTTPREADFILE: <file_name>,\(1-65535\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPSTOP=?',
        "match": 'AT\+QHTTPSTOP=\?\s{3}OK\s{2}',
    },
    # GET
    {
        "cmd": 'AT+QHTTPCFG="contextid",1',
        "match": 'AT\+QHTTPCFG="contextid",1\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPCFG="responseheader",1',
        "match": 'AT\+QHTTPCFG="responseheader",1\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QIACT?',
        "match": 'AT\+QIACT\?\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QICSGP=1,1,"UNINET","","" ,1',
        "match": 'AT\+QICSGP=1,1,"UNINET","","" ,1\s{3}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIACT=1',
        "match": 'AT\+QIACT=1\s{3}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIACT?',
        "match": 'AT\+QIACT\?\s{3}\+QIACT: 1,1,1,"[\.\d]+"\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPURL=245,80',
        "match": 'AT\+QHTTPURL=245,80\s{3}CONNECT\s{2}',
    },
    {
        "cmd": 'http://airtest.openluat.com:2900/?test1=1&test2=22&test3=333&test4=%E5%9B%9B%E5%9B%9B%E5%9B%9B%E5%9B%9B&test5=FiveFiveFiveFiveFive&test6=%E3%82%8D%E3%81%8F%E3%82%8D%E3%81%8F%E3%82%8D%E3%81%8F%E3%82%8D%E3%81%8F%E3%82%8D%E3%81%8F%E3%82%8D%E3%81%8F',
        "match": '\s{2}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPGET=80',
        "match": 'AT\+QHTTPGET=80\s{3}OK\s{4}\+QHTTPGET: 0,200,14\s{2}',
        "wait": b'+QHTTPGET: 0,200,14',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPREAD=80',
        "match": '\s{4}getTestSuccess\s{2}OK\s{4}\+QHTTPREAD: 0\s{2}',
        "wait": b'+QHTTPREAD: 0',
        "timeout": wait_timeout
    },
    # {
    #     "cmd": 'AT+QHTTPURL=44,80',
    #     "match": 'AT\+QHTTPURL=44,80\s{3}CONNECT\s{2}',
    # },
    # {
    #     "cmd": 'http://airtest.openluat.com:2900/redirect301',
    #     "match": '\s{2}OK\s{2}',
    # },
    # {
    #     "cmd": 'AT+QHTTPGET=80',
    #     "match": 'AT\+QHTTPGET=80\s{3}OK\s{4}\+QHTTPGET: 0,200,108025\s{2}',
    #     "wait": b'+QHTTPGET: 0,200,108025',
    #     "timeout": wait_timeout
    # },
    # {
    #     "cmd": 'AT+QHTTPREAD=80',
    #     "match": '.*',
    #     "wait": b'+QHTTPREAD: 0',
    #     "timeout": wait_timeout
    # },
    {
        "cmd": 'AT+QHTTPURL=44,80',
        "match": 'AT\+QHTTPURL=44,80\s{3}CONNECT\s{2}',
    },
    {
        "cmd": 'http://airtest.openluat.com:2900/redirect302',
        "match": '\s{2}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPGET=80',
        "match": 'AT\+QHTTPGET=80\s{3}OK\s{4}\+QHTTPGET: 0,200,227\s{2}',
        "wait": b'+QHTTPGET: 0,200,227',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPREAD=80',
        "match": '\s{2}OK\s{4}\+QHTTPREAD: 0\s{2}',
        "wait": b'+QHTTPREAD: 0',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="sslctxid",1',
        "match": 'AT\+QHTTPCFG="sslctxid",1\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QSSLCFG="sslversion",1,1',
        "match": 'AT\+QSSLCFG="sslversion",1,1\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QSSLCFG="ciphersuite",1,0x0005',
        "match": 'AT\+QSSLCFG="ciphersuite",1,0x0005\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QSSLCFG="seclevel",1,0',
        "match": 'AT\+QSSLCFG="seclevel",1,0\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPURL=21,80',
        "match": 'AT\+QHTTPURL=21,80\s{3}CONNECT\s{2}',
    },
    {
        "cmd": 'https://www.baidu.com',
        "match": '\s{2}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPGET=80',
        "match": 'AT\+QHTTPGET=80\s{3}OK\s{4}\+QHTTPGET: 0,200,227\s{2}',
        "wait": b'+QHTTPGET: 0,200,227',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPREAD=80',
        "match": '\s{2}OK\s{4}\+QHTTPREAD: 0\s{2}',
        "wait": b'+QHTTPREAD: 0',
        "timeout": wait_timeout
    },
    # POST
    {
        "cmd": 'AT+QHTTPCFG="requestheader",1',
        "match": 'AT\+QHTTPCFG="requestheader",1\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPURL=32,80',
        "match": 'AT\+QHTTPURL=32,80\s{3}CONNECT\s{2}',
    },
    {
        "cmd": 'http://airtest.openluat.com:2900',
        "match": '\s{2}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPPOST=107,80,80',
        "match": 'AT\+QHTTPPOST=107,80,80\s{3}CONNECT\s{2}',
        "wait": b'CONNECT',
        "timeout": wait_timeout
    },
    {
        "cmd": 'POST / HTTP/1.1\r\nHost: airtest.openluat.com:2900\r\nContent-Type: text/plain\r\nContent-Length: 8\r\n\r\nPostTest',
        "match": '\s{2}OK\s{4}\+QHTTPPOST: 0,200,15\s{2}',
        "wait": b'+QHTTPPOST: 0,200,15',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPREAD=80',
        "match": '\s{4}postTestSuccess\s{2}OK\s{4}\+QHTTPREAD: 0',
        "wait": b'+QHTTPREAD: 0',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPCFG="requestheader",0',
        "match": 'AT\+QHTTPCFG="requestheader",0\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QHTTPURL=48,80',
        "match": 'AT\+QHTTPURL=48,80\s{3}CONNECT\s{2}',
    },
    {
        "cmd": 'http://airtest.openluat.com:2900/calcPostDataLen',
        "match": '\s{2}OK\s{2}',
    },
    {
        "cmd": 'AT+QFUPL="1.txt",1024',
        "match": 'AT\+QFUPL="1.txt",1024\s{3}CONNECT',
    },
    {
        "cmd": open("static/1024.txt", "rb").read().decode(encoding="utf-8"),
        "match": '\s{2}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPPOSTFILE="1.txt",80',
        "match": 'AT\+QHTTPPOSTFILE="1.txt",80\s{3}OK\s{4}\+QHTTPPOSTFILE: 0,200\s{2}',
        "wait": b'+QHTTPPOSTFILE: 0,200',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPREAD=80',
        "match": '\s{2}OK\s{4}\+QHTTPREAD: 0\s{2}',
        "wait": b'+QHTTPREAD: 0',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QHTTPSTOP',
        "match": 'AT\+QHTTPSTOP\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QIDEACT=1',
        "match": 'AT\+QIDEACT=1\s{3}OK\s{2}',
    },
]
